#include "widget_header_buttons.h"
#include "ui_widget_header_buttons.h"
#include "defines.h"
#include "mainwindow.h"

widget_header_buttons::widget_header_buttons(QWidget *parent) :
    QFrame(parent),
    ui(new Ui::widget_header_buttons)
{
    ui->setupUi(this);

    if (g_currentSession == STUDENT_SESSION)
    {
        ui->student_list_view->hide();
        ui->messageLabel->hide();
        ui->alarmLabel->hide();
    }

    if (g_currentSession == PROCTOR_SESSION)
    {
        ui->test_list_view->hide();
        QObject::connect(ui->messageLabel,SIGNAL(clicked(QMouseEvent*)),this,SLOT(on_messagesLabel_clicked()));
        QObject::connect(ui->alarmLabel,SIGNAL(clicked(QMouseEvent*)),this,SLOT(on_alarmLabel_clicked()));
    }

    if (g_currentSession == TEACHER_SESSION)
    {
        ui->messageLabel->hide();
        ui->alarmLabel->hide();
    }

    if (g_mainWindow->getCurrentScene() == TEST_LIST_VIEW)
    {
        ui->test_list_view->setDisabled(true);
    }

    if (g_mainWindow->getCurrentScene() == STUDENT_LIST_VIEW)
    {
        ui->student_list_view->setDisabled(true);
    }

    if (!g_mainWindow->hasHistory())
    {
        ui->back_button->setDisabled(true);
    }
}

widget_header_buttons::~widget_header_buttons()
{
    delete ui;
}

void widget_header_buttons::on_back_button_clicked()
{
    g_mainWindow->onchangeScene(g_mainWindow->getLastScene());
}

void widget_header_buttons::on_logout_button_clicked()
{
    g_mainWindow->nukeHistory();
    g_mainWindow->onchangeScene(SIGN_IN_VIEW);
}

void widget_header_buttons::on_student_list_view_clicked()
{
    g_mainWindow->onchangeScene(STUDENT_LIST_VIEW);
}

void widget_header_buttons::on_test_list_view_clicked()
{
    g_mainWindow->onchangeScene(TEST_LIST_VIEW);
}


void widget_header_buttons::on_messageLabel_clicked()
{
    g_mainWindow->onchangeScene(STUDENT_LIST_VIEW);
}

void widget_header_buttons::on_alarmLabel_clicked()
{
    g_mainWindow->onchangeScene(STUDENT_LIST_VIEW);
}
